package com.gmail.mariska.martin.model;

import java.util.Date;
import java.util.Random;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.gmail.mariska.martin.jpa.EntityListener;
import com.gmail.mariska.martin.jpa.IDatinAble;

@Entity
@Table(name = "DOGS")
@EntityListeners(EntityListener.class)
public class Dog implements IDatinAble {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	private String name;
	private Date datin;
	private double weight;

	private final int rand = new Random().nextInt();

	@Transient
	public double getRand() {
		return rand;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getWeight() {
		return weight;
	}

	public void setWeight(double weight) {
		this.weight = weight;
	}

	@Override
	public String toString() {
		return String.format("Dog[id=%d, name=%s, weight=%f, rand=%d]", this.id, this.name, this.weight, this.rand);
	}

	@Override
	public int hashCode() {
		return getId();
	}

	@Override
	public boolean equals(Object obj) {

		if (obj instanceof Dog) {
			Dog dog = (Dog) obj;
			return dog.getId() == getId();
		}

		return false;
	}

	@Override
	public Date getDatin() {
		return datin;
	}

	@Override
	public void setDatin(Date datin) {
		this.datin = datin;
	}
}
